<?php
// @formatter:off
/**
 * @file WCRss.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-22 17:58:11 +0000 (Sat, 22 Jun 2013) $
 *
 * $Id: WCRss.php 83 2013-06-22 17:58:11Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA2/includes/WCRss.php $
 */
// @formatter:on

require_once "{$wcPaths["includes-directory"]}/WCRssItem.php";

/**
 * @class WCRss
 */
class WCRss {
	protected $_dateFormat = "r";
	protected $_items = array();
	protected $_values = array(
		"title" => "",
		"description" => "",
		"link" => "",
		"lastBuildDate" => "",
		"pubDate" => "",
		"ttl" => ""
	);

	public function __construct() {
		$this->lastBuildDate = time();
		$this->pubDate = time();
	}
	//
	// Public methods.
	public function __get($name) {
		if(!isset($this->_values[$name])) {
			trigger_error(__CLASS__.": Property '{$name}' not defined", E_USER_ERROR);
		}

		return $this->_values[$name];
	}
	public function __set($name, $value) {
		if(!isset($this->_values[$name])) {
			trigger_error(__CLASS__.": Property '{$name}' not defined", E_USER_ERROR);
		}

		$this->_values[$name] = $value;

		return $this->$name;
	}
	public function addItem(WCRssItem $item) {
		$this->_items[] = $item;
	}
	public function reset() {
		$this->_items = array();
		foreach($this->_values as $property => $value) {
			$this->_values[$property] = "";
		}
	}
	public function setDateFormat($format = "") {
	}
	public function xml() {
		$out = "";

		$out .= "<?xml version=\"1.0\"?>";
		//$out .= "<?xml-stylesheet href=\"includes/rss.xlst\" type=\"text/xsl\"
		// media=\"screen\"? >";
		$out .= "<rss version=\"2.0\">";
		$out .= "<channel>";
		$out .= "<title>".WCRSS::Satinaze($this->title)."</title>";
		$out .= "<description>".WCRSS::Satinaze($this->description)."</description>";
		$out .= "<link>".WCRSS::Satinaze($this->link)."</link>";
		//$out .= "<lastBuildDate>".date($this->_dateFormat,
		// $this->lastBuildDate)."</lastBuildDate>";
		$out .= "<pubDate>".WCRSS::Satinaze(date($this->_dateFormat, $this->pubDate))."</pubDate>";
		//$out .= "<ttl>{$this->ttl}</ttl>";

		foreach($this->_items as $item) {
			$out .= $item->xml();
		}

		$out .= "</channel>";
		$out .= "</rss>";

		return $out;
	}
	//
	// Public class methods.
	public static function Satinaze($value) {
		return htmlentities($value);
	}
}
?>